#ifndef	_GEN_TYPE_DEF_H
#define	_GEN_TYPE_DEF_H
//
#ifdef __cplusplus
extern "C" {
#endif
//
#pragma  pack (1)
//----------------data type definition-------------                    
typedef	 unsigned char          uCHAR;	     // 1 byte
typedef	 unsigned short         uSHORT;	     // 2 bytes
typedef  unsigned long          uLONG;	     // 4 bytes
//
typedef  signed  char           CHAR;	     // 1 byte
typedef	 signed  short          SHORT;	     // 2 bytes
typedef	 signed  long           LONG;	     // 4 bytes
//
typedef  float                  FLOAT;       // 4 bytes

//*********************************************************
//     ---- Please add your type definition here----
//*********************************************************
//-----------------enum  type  definition---------
typedef	enum{FALSE = 0,TRUE = 1}T_BOOL;
//
typedef	enum{NONE = 0,OFF = 1,ON = 2,A_L_B_PWM = 3,A_L_B_H = 4}T_PWM_STATUS;
//
typedef	enum{INIT_STAGE = 0,NONE_STAGE = 1,FIRST_STAGE = 2,SECOND_STAGE = 3,THIRD_STAGE = 4,BRAKE_STAGE = 5}T_STAGE;
//
typedef	enum{INDEX_START = 0,INDEX_1 = 1,INDEX_2 = 2,INDEX_3 = 3,INDEX_4 = 4,INDEX_5 = 5,INDEX_6 = 6,INDEX_7 = 7,INDEX_8 = 8,
INDEX_9 = 9,INDEX_10 = 10,INDEX_11 = 11,INDEX_12 = 12,INDEX_13 = 13,INDEX_14 = 14,INDEX_15 = 15,INDEX_END = 255}T_INDEX;
//
typedef	enum{SECTOR_NONE = 0,SECTOR_1 = 1,SECTOR_2 = 2,SECTOR_3 = 3,SECTOR_4 = 4,SECTOR_5 = 5,SECTOR_6 = 6}T_SECTOR;
//
typedef	enum{TYPE_NONE = 0,TYPE_1 = 1,TYPE_2 = 2,TYPE_3 = 3,TYPE_4 = 4}T_TRIGTYPE;
//
typedef	enum{LOCATION = 0,OPEN_LOOP = 1,CLOSED_LOOP = 2}T_FOC_INDEX;
//
//-----------------end enum  type  definition-----
//
//------------------struct type and union type definiton---------
typedef struct{
    uCHAR  Sys1ms                   :1;         // system 1ms flag
    uCHAR  SysOnOff                 :1;         // system onoff flag
    uCHAR  speed_update_ok          :1;
    uCHAR  speed_fst                :1;
    uCHAR  adp_LPF_coeff_fst        :1;
    uCHAR  adp_LPF_coeff_en         :1;
    uCHAR  open_loop_time           :1;
    uCHAR  bit7                     :1;
    //
    uCHAR  key1                 :1;
    uCHAR  key2                 :1;
    uCHAR  key1_fun             :1;
    uCHAR  key2_fun             :1;
    uCHAR  check_sector_fst     :1;
    uCHAR  check_sector_ok      :1;
    uCHAR  ibus_fst             :1;
    uCHAR  debug_save_ok        :1;
    //
    uCHAR  bit16    :1;
    uCHAR  bit17    :1;
    uCHAR  bit18    :1;
    uCHAR  bit19    :1;
    uCHAR  bit20    :1;
    uCHAR  bit21    :1;
    uCHAR  bit22    :1;
    uCHAR  bit23    :1;
}T_FLAG;
//
typedef struct{
    uCHAR  led      :1;
    uCHAR  ocp      :1;
    uCHAR  uvp      :1;
    uCHAR  otp      :1;
    uCHAR  acp     :1;
    uCHAR  lrpp     :1;
    uCHAR  lrcp     :1;
    uCHAR  ovp      :1;
    //
    uCHAR  dir_rot  :1;
    uCHAR  key1     :1;
    uCHAR  key2     :1;
    uCHAR  bit11    :1;
    uCHAR  bit12    :1;
    uCHAR  bit13    :1;
    uCHAR  bit14    :1;
    uCHAR  bit15    :1;
}T_DELAY;
//
typedef struct{
    uCHAR  led      :1;
    uCHAR  ocp      :1;
    uCHAR  uvp      :1;
    uCHAR  otp      :1;
    uCHAR  acp     :1;
    uCHAR  lrpp     :1;
    uCHAR  lrcp     :1;
    uCHAR  ovp      :1;
    //
    uCHAR  dir_rot  :1;
    uCHAR  key1     :1;
    uCHAR  key2     :1;
    uCHAR  bit11   	:1;
    uCHAR  bit12  	:1;
    uCHAR  bit13   	:1;
    uCHAR  bit14    :1;
    uCHAR  bit15    :1;
}T_TIMEOUT;
//
typedef union {
    uSHORT wordprt;
    //
    struct{
        uCHAR byte0;
        uCHAR byte1;
    }byteprt;
    //
    struct{
        uCHAR lrcp	: 1;  // the LRCP flag
        uCHAR lrpp	: 1;  // the LRPP flag
        uCHAR otp	: 1;  // the OTP flag
        uCHAR uvp	: 1;  // the UVP flag
        uCHAR ovp	: 1;  // the OVP flag
        uCHAR ocp	: 1;  // the OCP flag
        uCHAR acp	: 1;
        uCHAR bit7	: 1;
        //
        uCHAR bit8	: 1;
        uCHAR bit9	: 1;
        uCHAR bit10	: 1;
        uCHAR bit11	: 1;
        uCHAR bit12	: 1;
        uCHAR bit13	: 1;
        uCHAR bit14	: 1;
        uCHAR bit15	: 1;
	}bitprt;
}T_PROTECT;
//
typedef struct 
{
    SHORT IComp_1;
    SHORT IComp_2;
}T_CurrComps;
//
typedef struct 
{
    LONG IComp_1;
    LONG IComp_2;
}T_CurrComps32;
//
typedef struct 
{
    SHORT VComp_1;
    SHORT VComp_2;
}T_VoltComps;
//
typedef struct 
{
    LONG VComp_1;
    LONG VComp_2;
}T_VoltComps32;
//
typedef struct
{
    SHORT Cos;
    SHORT Sin;
}T_TrigComps;
//
typedef struct {
    T_SECTOR    Sector;
    T_TRIGTYPE  TrigType;
    uSHORT      TMR1_CC1;
    uSHORT      TMR1_CC2;
    uSHORT      TMR1_CC3;
    uSHORT      TMR1_CC4;
    uSHORT      TMR3_CC1;
    uSHORT      TMR3_CC2;
    uSHORT      TMR3_CC4;
}T_SVPWMComps;
//
typedef struct {
    LONG  Ref;          // the set data
    LONG  Fdb;          // the feedbacck data
    //
    LONG  Err;          // e(k),the error
    LONG  ErrBak;       // e(k-1),the error
    //
    LONG  Kp;           // parameter P
    LONG  Ki;           // parameter I
    //
    LONG  Uout;         // Uout(k)
    LONG  UoutBak;      // Uout(k-1)
    //
    LONG  OutMax;       // the maximum data of the final output data 
    LONG  OutMin;       // the minimum data of the final output data 
}T_INC_PID;
//
typedef struct {
    LONG   ErrorMax;            // the maximum error of Bang-Bang Controller
    LONG   Gain_K;              // the gain K of Bang-Bang Controller
    LONG   CorrFactor_1;        // the correction factor voltage 1
    LONG   CorrFactor_2;        // the correction factor voltage 2
    SHORT  LPFCoeff;            // the Low pass filter coefficient
    SHORT  Angle;               // the electrical angle
    uLONG  KSpeed;              // the speed constant
}T_SLIDE_MODE_CTRL;
//
typedef struct {
    LONG  Gain_F;              // the gain F of motor digital model
    SHORT Gain_F_Quo;          // the integer part of Gain_F
    SHORT Gain_F_Rem;          // the fractional part of Gain_F
    //
    LONG  Gain_G;              // the gain G of motor digital model
    SHORT Gain_G_Quo;          // the integer part of Gain_G
    SHORT Gain_G_Rem;          // the fractional part of Gain_G
    //
    T_CurrComps32  CurrEst;     // the estimating current
    T_VoltComps32  BEMF_First;  // the BEMF after the first low pass filtering
    T_VoltComps32  BEMF_Second; // the BEMF after the second low pass filtering
}T_MOTOR_DIG_MODE;
//
//------------------end struct type and union type definiton---------
//
#ifdef __cplusplus
}
#endif
//
#endif //_GEN_TYPE_DEF_H


